<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class orderModel extends Model{
    public $table = 'order';

    /**
     * @param int $id
     * @param int $type 1:用户  ，0:店铺
     * 订单明细
     */
    public function orderDel($id = 0,$type = 0){
        $type === 0 ? $where['shop_id'] = $id : $where['user_id'] = $id;
        $list = Db::name($this->table)->where($where)->select();

    }
    public function orderStatus(){
        $arr = [
            0=>'待支付',
            1=>'已支付',
            2=>'支付失败',
        ];
        return $arr;
    }

    /**
     * @param array $list
     * @param array $arr
     * 获取状态名称
     */
    public function getOrStNa($list=array(),$arr=array()){
        $arr == [] ? $arr = self::orderStatus() :$arr = [];
        foreach ($list as $k=>$v){
            foreach ($arr as $key=>$item){
                if($v['status'] == $key){
                    $list[$k]['statusName'] = $item;
                }
            }
        }
        return $list;
    }

    /**
     * @param array $list
     */
    public function getSn($list =0,$field =''){
     if($list){
         $id = [];
         foreach ($list as $value){
             $value['order_id'] !='' ? $id[] = $value['order_id'] :'';
         }
         if($id){
             $strId = implode(',',$id);
             $where ="id in($strId)";
             $ar = Db::name($this->table)->where($where)->field('id,sn')->select();
             foreach ($list as $k=>$v){
                 foreach ($ar as $item){
                     if($v['order_id'] == $item['id']){
                         $list[$k]['sn'] = $item['sn'];
                     }
                 }
             }
         }
     }
        return $list;
    }

}